package com.cy.pj.eiems.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cy.pj.eiems.Exception.ServiceException;
import com.cy.pj.eiems.entity.Question;
import com.cy.pj.eiems.entity.Score;
import com.cy.pj.eiems.service.SysExamService;
import com.cy.pj.eiems.vo.JsonResult;
import com.cy.pj.eiems.vo.PageObject;


@Controller
@RequestMapping("/exam/")
public class SysExamController {

	@Autowired
	private SysExamService sysExamService;

	/**
	 * 随机获取指定数量(暂时固定数量)考题并呈现 方法
	 * @param knowledgePoint
	 * @return
	 */
	@RequestMapping("doFindRandomQuestions") 
	@ResponseBody
	public JsonResult doFindRandomQuestions() {
		List<Question> findQuestions = sysExamService.findQuestions();
		System.out.println("这是exam模块展示题功能的Controller的方法,返回的数据是:" + findQuestions);
		return new JsonResult(findQuestions);
	}

	//	/**
	//	 * 根据"知识点"查询考题呈现方法
	//	 */
	//	@RequestMapping("doFindQuestionsByKnowledgePoint")
	//	@ResponseBody
	//	public JsonResult doFindQuestionsByKnowledgePoint() {
	//		return new JsonResult();
	//	}

	/**
	 * "交卷"
	 * 	记录成绩
	 * 	保存错题集
	 */
	@RequestMapping("doReturnResults")
	@ResponseBody
	public JsonResult doReturnResults(String username, Integer score) {
		System.out.println("我是存分数的controller层,我拿到的数据是:" + username + score);
		int saveResults = sysExamService.saveResults(username, score);
		if(saveResults<1)throw new ServiceException("保存失败了啊!");
		return new JsonResult("考试结束，可移步“历史成绩”查看成绩!");
	}

	/**
	 * 分页查询score信息
	 */
	@RequestMapping("doFindPageObjects")
	@ResponseBody
	public JsonResult doFindPageObjects(String username,Integer pageCurrent){
		System.out.println("这是exam模块展示题功能的Controller的方法,拿到的数据是:" + username + pageCurrent);
		PageObject<Score> pageObject=
				sysExamService.findPageObjects(username,pageCurrent);
		System.out.println("这是exam模块展示题功能的Controller的方法,返回的数据是:" + pageObject);
		return new JsonResult(pageObject);
	}



}
